<?php
/**
 * 
 * FGallery.php
 * @package Foundation
 *
 */

/**
 * FGallery
 * 
 * @author mw
 * @package Foundation
 */
class FGallery extends Fdatabase{
	/**
	 * Costruttore
	 */
	public function __construct() {
		parent::__construct('EGallery','gallery','id');
	}
	/**
	 * getGalleryIscritti
	 * @param string $username
	 * @param int $limit
	 */
	public function getGalleryIscritti($username,$limit){
		
		$query = 'SELECT * 
				  FROM gallery 
				  WHERE username IN (
    			  	SELECT iscritto.iscritto 
    			  	FROM iscritto 
    			  	WHERE username = "'.$this->safeString($username).'")
				  ORDER BY gallery.id DESC
				  LIMIT 0,'.$limit.';';
		
		$this->_query($query);
	}
	/**
	 * getGalleryAmici
	 * @param string $username
	 * @param int $limit
	 */
	public function getGalleryAmici($username,$limit){
	
		$query = 'SELECT *
		FROM gallery
		WHERE username IN (
			SELECT amico.amico2
			FROM amico
			WHERE amico1 = "'.$this->safeString($username).'" AND confermato = 1)
		ORDER BY gallery.id DESC
		LIMIT 0,'.$limit.';';
	
		$this->_query($query);
	}
	/**
	 * delete
	 * @param string $where
	 * @throws ExceptionDB
	 */
	public function delete($where){
		
		parent::query('UPDATE foto SET galleryid=0 WHERE galleryid=\''.$this->safeString($where['id']).'\';');
		parent::delete($where);
		
	}
	
	
}